/**
 * Copyright (c) 2011-2012 Tomi Paananen.
 *
 * Part of Quick Gestures application.
 */

// Qt includes
#include <QApplication>
#include <QDeclarativeView>
#include <QDeclarativeEngine>
#include <QDeclarativeContext>
#include <QObject>
#include <QtDeclarative>

#ifdef Q_OS_SYMBIAN
    // Symbian specific includes
    #include <aknappui.h>
#endif

// qgengine includes
#include <quickgesturesengine.h>
#include <gesture.h>
#include <gesturemodel.h>
#include <storagemanager.h>
#include <storagethread.h>
#include <qgtrace.h>

// qgui includes
#include "gesturehelper.h"
#include "gesturevisualizer.h"


int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    // Register the engine types.
    qmlRegisterType<Gesture>("QuickGestures", 1, 0, "Gesture");
    qmlRegisterType<GestureModel>("QuickGestures", 1, 0, "GestureModel");
    qmlRegisterType<QuickGesturesEngine>("QuickGestures", 1, 0, "QuickGesturesEngine");
    qmlRegisterType<StorageThread>("QuickGestures", 1, 0, "StorageThread");

    // Register the custom QML elements.
    qmlRegisterType<GestureVisualizer>("QuickGestures", 1, 0, "GestureVisualizer");

    QDeclarativeView view;
    view.setResizeMode(QDeclarativeView::SizeRootObjectToView);

    GestureHelper helper;
    view.rootContext()->setContextProperty("helper", &helper);

    QObject::connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit()));

    view.setSource(QUrl("qrc:/main.qml"));

#ifdef Q_WS_MAEMO_6
    // Disable the exit button.
    QObject *rootObject = dynamic_cast<QObject*>(view.rootObject());

    if (rootObject) {
        rootObject->setProperty("exitButtonEnabled", false);
    }
    else {
        DEBUG_INFO("Failed to get the root object!");
    }
#endif

#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
    DEBUG_INFO("Running on mobile device.");

#ifdef Q_OS_SYMBIAN
    view.setAttribute(Qt::WA_NoSystemBackground);
#endif

    view.showFullScreen();
#elif defined(Q_WS_SIMULATOR)
    DEBUG_INFO("Running in simulator.");
    view.showFullScreen();
#else
    DEBUG_INFO("Running in desktop environment?");
    view.setGeometry(QRect(0, 0, 480, 854));
    view.show();
#endif

    return app.exec();
}

// End of file.
